<template>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
        <tr>
            <td>
                <el-form-item label="计划编码">
                    <el-input v-model="form.planningCode" disabled/>
                </el-form-item>
            </td>
            <td>
                <el-form-item label="计划名称">
                    <el-input v-model="form.planningName" />
                </el-form-item>
            </td>
        </tr>
        <tr>
            <td>
                <el-form-item label="计划描述">
                    <el-input v-model="form.planningDesc" />
                </el-form-item>
            </td>
            <td>
                <el-form-item label="状态">
                    <el-select v-model="form.planningState" placeholder="请选择" disabled>
                        <el-option label="新建" :value=true />
                    </el-select>
                </el-form-item>
            </td>
        </tr>
        <tr>
            <td>
                <el-form-item label="制单人">
                    <el-input v-model="form.planningPeole" disabled/>
                </el-form-item>
            </td>
            <td>
                <el-form-item label="制单部门">
                    <el-select v-model="form.departmentId" placeholder="请选择" disabled>
                        <el-option label="JAVA组" :value=1  />
                    </el-select>
                </el-form-item>
            </td>
        </tr>
        <el-button type="success" @click="upd()">修改</el-button>
    </el-form>
    <el-table :data="list" style="width: 100%">
        <el-table-column prop="planningRow" label="行号" />
        <el-table-column prop="chooseId" label="物料名称">
            <template v-slot="scope">
                <span v-if="scope.row.chooseId == 1">棉花</span>
                <span v-else>羊皮</span>
            </template>
        </el-table-column>
        <el-table-column prop="unitName" label="单位" />
        <el-table-column prop="spec" label="规格" />
        <el-table-column prop="chooseId" label="物料属性">
            <template v-slot="scope">
                <span v-if="scope.row.chooseId == 1">自制</span>
                <span v-else-if="scope.row.chooseId == 2">采购</span>
                <span v-else>委外</span>
            </template>
        </el-table-column>
        <el-table-column prop="planningNum" label="计划数量" />
        <el-table-column prop="planningNum" label="实际需求数量" />
        <!-- <el-table-column prop="address" label="库存量">
            
        </el-table-column>
        <el-table-column prop="date" label="预计接收量" /> -->
        <el-table-column prop="planningStartDate" label="计划开工日期">
            <template v-slot="scope">
                {{ scope.row.planningStartDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="planningEndDate" label="计划完工日期">
            <template v-slot="scope">
                {{ scope.row.planningEndDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="pid" label="下达状态">
            <template v-slot="scope">
                <span v-if="scope.row.pid == 1">开始</span>
                <span v-else>结束</span>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template v-slot="scope">
                <el-button>删除</el-button>
                <el-button>编辑</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'
import axios from 'axios'
const apiurls = import.meta.env.VITE_APP_API_URL_ProductionAdd;
const apiurl = import.meta.env.VITE_APP_API_URL_ProductionShow;
const router = useRouter()
const route = useRoute()
const form = reactive({
    materialPlanningId: route.query.materialPlanningId,
    planningCode: "",
    planningName: "",
    planningDesc: "",
    planningState: "",
    planningPeole: "",
    departmentId: "",
    handle: "Admin",
    handleContext: "新增",
    handleTime: "",
    pid: 1,
    isDelete: false
});
//反填物料需求计划
const add = () => {
    axios.post(apiurl + '/api/ShowMaterial/GetMaterialPlan', {
        materialPlanningId: form.materialPlanningId,
    }).then(res => {
        form.materialPlanningId = res.data.data.materialPlanningId
        form.planningCode = res.data.data.planningCode
        form.planningName = res.data.data.planningName
        form.planningDesc = res.data.data.planningDesc
        form.planningState = res.data.data.planningState
        form.planningPeole = res.data.data.planningPeole
        form.departmentId = res.data.data.departmentId
    })
}
const upd = () => {
    axios.post(apiurls + '/api/Material/UpdateMaterialPlanning', {
        materialPlanningId: form.materialPlanningId,
        planningCode: form.planningCode,
        planningName: form.planningName,
        planningDesc: form.planningDesc,
        planningState: true,
        planningPeole: form.planningPeole,
        departmentId: form.departmentId,
        IsDelete: false,
        handle: form.handle,
        handleContext: form.handleContext,
        handleTime: new Date(),
        pid: form.pid

    }).then(res => {
        console.log(res.data.code)
        if (res.data.code > 0) {
            ElMessage.success("修改成功")
            router.push({ name: 'MaterialPlanningList' })
        } else {
            ElMessage.error("修改失败")
        }
    })
}
//行显示
const list = ref([])
const getlist = () => {
    axios.post(apiurl + '/api/ShowMaterial/GetRowMaterialPlanning', {

    }).then(res => {
        console.log(res.data)
        list.value = res.data.data

    })
}
onMounted(() => {
    add()
    getlist()
})
</script>